import "package:flutter/material.dart";
import "package:myapp/_views/home/widget/animate/AnimateCard_1.dart";
import "animate.class.dart";

class AnimateHot extends StatelessWidget {
  final List<dynamic> list;
  const AnimateHot({super.key, required this.list});
  @override
  Widget build(BuildContext context) {
    // 处理成每行两个的二维数组 [[1,1],[1,1]]
    List<List<AnimateHotItem>> slist = [];
    List<AnimateHotItem> row = [];
    for (int i = 0; i < list.length; i++) {
      AnimateHotItem item = list[i];
      row.add(item);
      if (row.length == 2) {
        slist.add(row);
        row = [];
      }
      if (i == list.length - 1 && row.isNotEmpty) {
        slist.add(row);
      }
    }
    double columnGap = 6;
    return SliverList.builder(
      itemCount: slist.length,
      itemBuilder: (BuildContext context, int index) {
        List<AnimateHotItem> row = slist[index];
        List<Widget> rowW = [];
        for (int i = 0; i < row.length; i++) {
          AnimateHotItem item = row[i];
          double marginLeft = columnGap / 2;
          double marginRight = columnGap / 2;
          if (i == 0) {
            marginLeft = columnGap;
          } else if (i == row.length - 1) {
            marginRight = columnGap;
          }
          rowW.add(
            Container(
              margin: EdgeInsets.only(left: marginLeft, right: marginRight),
              child: AnimateCard1(
                item: item,
              ),
            ),
          );
        }
        return Container(
          width: double.infinity,
          margin: const EdgeInsets.only(bottom: 9),
          child: IntrinsicHeight(
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: rowW.map((e) => Expanded(child: e)).toList(),
            ),
          ),
        );
      },
    );
  }
}
